Ext.onReady(function(){

	//================================================================
	// Set ExtJS proterty.
	//================================================================
	Ext.BLANK_IMAGE_URL = m_ContextName + '/common/ext-2.2/resources/images/default/s.gif';
	Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	Ext.QuickTips.init();
	
	//================================================================
	// Set Layout using Ext Viewport
	//================================================================
	var pbarMain = new Ext.ProgressBar({
		text: 'Scan을 준비중입니다...',
		id: 'id_pbar_main',
		textEl: 'id_span_pbar_text',
		cls: 'custom',
		renderTo: 'id_div_pbar'
	});
	
	
	var viewport = new Ext.Viewport({
		layout: 'border',
		items: [
			new Ext.Panel({
				region: 'center',
				id: 'id_panel_menu',
				contentEl: 'id_div_panel_div',
				title: 'search',
				margins: '0 0 0 0',
				bodyStyle: 'padding:10px 10px 10px 10px',
				items: pbarMain,
				buttonAlign: 'right',
				buttons: [{
					id: 'id_btn_close',
					text: '취소',
					handler: function() {
						window.close();
					}
				},{
					id: 'id_btn_ok',
					text: '확인',
					handler: fnActionComplete,
					disabled: true
				}]
			})
		]
	});
	
	
	fnAjaxContents();
	
	
	storeList.on('load', function(){
		fnViewList();
		
		Runner.run(pbarMain, 19, function() {
			pbarMain.updateText('검사가 완료되었습니다.');
			m_isListCount = false;
			
			$('id_div_text_scan_count').innerHTML = '검출된 취약점 항목 수 : <b>' + (m_AnalysisType1 + m_AnalysisType2 + m_AnalysisType3 + m_AnalysisType4) + '</b>개';
			$('id_div_text_file_count').innerHTML = '검사한 항목 수 : <b>' + storeList.getCount() + '</b>';
			
			$('id_div_text_1').innerHTML = 'SQL Injection 취약점 (<b>' + m_AnalysisType1 + '</b>)';
			$('id_div_text_2').innerHTML = 'XSS(Cross Site Scripting) 취약점 (<b>' + m_AnalysisType2 + '</b>)';
			$('id_div_text_3').innerHTML = '파일 업로드 취약점 (<b>' + m_AnalysisType3 + '</b>)';
			$('id_div_text_4').innerHTML = 'CSRF 취약점 (<b>' + m_AnalysisType4 + '</b>)';
			
			Ext.getCmp('id_btn_ok').enable();
		});
	});
	
});

	
	



// 프로그래스바 Status
var Runner = function() {
	var f = function(v, pbar, count, cb) {
		return function() {
			if (v > count)
			{
				cb();
			}else{
				if (pbar.id == 'id_pbar_main')
				{
					var i = v/count;
					pbar.updateProgress(i, Math.round(100*i) + '% completed...');
				}else{
					pbar.updateProgress(v/count, 'Loading item ' + v + ' of ' + count + '...');
				}
			}
		};
	};
	return {
		run: function(pbar, count, cb) {
			var ms = 10000/count;
			for (var i=1; i<(count+2); i++) {
				setTimeout(f(i, pbar, count, cb), i*ms);
			}
		}
	}
}();

// 파일목록 로딩
function fnViewList()
{
	if(m_isListCount == true)
	{
		var strPath = storeList.getAt(m_ListCount).data.file_path;
		var strName = storeList.getAt(m_ListCount).data.file_name;
		
		$('id_div_text_file_count').innerHTML = '검사한 항목 수 : ' + strPath + '\\' + strName;
		m_ListCount++;
		
		setTimeout('fnViewList()', 100);
	}
}

// 처리완료시
function fnActionComplete()
{
	opener.top.frameTree.location.href = m_ContextName + '/analysis/analysis700Main.do?type=2&ip=' + m_SiteName;
	opener.top.frameContents.location.href = m_ContextName + '/analysis/analysis500Main.do?find1=' + m_AnalysisType1 + '&find2=' + m_AnalysisType2 + '&find3=' + m_AnalysisType3 + '&find4=' + m_AnalysisType4;
	window.close();
}
	

	
	
	
	
	
	
	
	
	
	
	